package cn.tt.tuantuanerp.tuantuanerp.purchase.webapi.controller;
import cn.tt.tuantuanerp.tuantuanerp.comment.pojo.dto.SupplierStandardDTO;
import cn.tt.tuantuanerp.tuantuanerp.comment.pojo.vo.SupplierStandardListVO;
import cn.tt.tuantuanerp.tuantuanerp.comment.pojo.vo.SupplierStandardVO;
import cn.tt.tuantuanerp.tuantuanerp.comment.web.JsonPage;
import cn.tt.tuantuanerp.tuantuanerp.comment.web.JsonResult;
import cn.tt.tuantuanerp.tuantuanerp.purchase.service.ISupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zms
 * 供应商控制类
 */

@RestController
@Api(tags = "2.供应商模块")
@RequestMapping("/suppliers")
public class SupplierController {
    @Autowired
    ISupplierService service;
    /**
     * @author zms
     * 新增供应商
     */
    @PostMapping("/add")
    /*@PreAuthorize("hasAuthority('purch_staff')")*/
    public JsonResult<Void> add(SupplierStandardDTO supplier){
        service.add(supplier);
        return  JsonResult.ok();
    }

    /**
     * @author zms
     * 根据id删除供应商
     */
    @ApiOperation("删除供应商")
    @PostMapping("/deleteById/{id}")
    @PreAuthorize("hasAuthority('purch_staff')")
    public  JsonResult<Void> deleteById(@PathVariable Integer id){
        service.deleteById(id);
        return  JsonResult.ok();
    }
    /**
     * @author zms
     * 根据id查询供应商
     */
    @ApiOperation("查询供应商")
    @PostMapping("/getById/{id}")
    @PreAuthorize("hasAuthority('purch_staff')")
    public JsonResult getById(@PathVariable Integer id){
        SupplierStandardVO supplierStandardVO = service.ById ( id );
        return  JsonResult.ok(supplierStandardVO);
    }

    /**
     * @author zms
     * 查询供应商列表
     */
    @ApiOperation("供应商列表")
    @GetMapping("/list")
    public  JsonResult<JsonPage<SupplierStandardListVO>> list(Integer startIndex, Integer pageSize){
        return JsonResult.ok(service.list(startIndex, pageSize));
    }

    /**
     * @author zms
     * 查询列表（不分页）
     */
    @ApiOperation("查询列表（不分页）")
    @GetMapping("/noPage")
    public  JsonResult<List<SupplierStandardListVO>> listNoPage(){
       return JsonResult.ok(service.listNoPage());
    }
}
